<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/temp.dwt" codeOutsideHTMLIsLocked="false" -->
<%@page import="com.crm.entity.Opportunity,com.crm.entity.Supplier,java.util.*" %>
<head>

<script src="<%=application.getContextPath()%>/js/jquery-1.6.min.js"></script> 
   

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<link href="<%=application.getContextPath()%>//css/css-crm.css" rel="stylesheet" type="text/css" />

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

</head>
<body>
<%List<Opportunity> opprtlist =(List<Opportunity>)request.getAttribute("opprtunity");%>
<div id="main">

   <%@ include file="common/header.jsp" %>
  <%@ include file="common/submenu.jsp" %>
  
  <div id="content">
  <div id="enqclient"  align="center" class="result_msg"></div>
  <div id="resultMsg"  align="center" class="result_msg">
    <% 
   String msg= request.getParameter("msgsrc");
    	if(msg!=null){
    		System.out.println(msg);
    		out.println(msg);
    	}
    	
    %>
    </div>
  <form id="impform" name="frm1" action="<%=application.getContextPath()%>/purchaseOrder/generatePO.do"  method="post">
    <div id="work-area2">
      <div class="heading2">Purchase Order</div>
	  
      <div class="boxIFS">
      
          <table width="100%"  style="height:80px;" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="12%" align="right">Reference No.</td>
              <td width="22%" align="right" valign="middle">
              <select name="reflist" class="form_select" id="reflistid">
                 <option value="">Please Select</option>
         <%if(opprtlist!=null){
        	 assert opprtlist!=null:"the size of the pr list is "+opprtlist.size();
	      	for(int i=0;i<opprtlist.size();i++){
	      	%>
           <option  value="<%=opprtlist.get(i).getRefNum()%>" ><%=opprtlist.get(i).getRefNum()%></option>
                   	<%}
	              	}%>
                </select></td>
              <td width="7%" align="left" valign="middle">Supplier</td>
              <td width="25%" align="left" valign="middle">
                <select name="supplier" class="form" id="supplierid">
                <option value="">Please Select</option>
                </select>
              </td>
              <td width="25%"><input type="button" id="getdetid" class="buttonleft"  value="Get Details"/></td>
            </tr>
          </table>
       
      </div>
      <div id="ajaxLoader" style="display:none" align="center"><img src="<%=application.getContextPath()%>/images/ajax_loader.gif"/></div>
	   <table style="height:300px; width:957px;" ><tr><td><div id="resTable" class="boxtable"></div></td></tr></table> 
	<!--  <div class="box2" id="resTable" style="display:none"> -->
        
      </div>
    </form>
    
    <!-- InstanceEndEditable -->
  </div><div id="footer"></div>  
</div>
</body>
<!-- InstanceEnd --></html>
<script type="text/javascript">

$("#getdetid").click(function(){
	var refno=$("#reflistid").val();
	var supplierName=$("#supplierid").val();
	var data="refno="+refno+"&supplierName="+supplierName;
  
	if(refno!=null && supplierName!=null){
		$("#ajaxLoader").show();
	$.ajax({
		url:"<%=application.getContextPath()%>/purchaseOrder/search.do",
		data:data,
		method:"post",
		mimetype: "text/html",
		success:function(res){			
			$("#resTable").html(res);
			$("#resTable").show();			
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
		/* alert("Ajax Loading Completed"); */
	}).fail(function(html){
		$("#ajaxLoader").hide();
		alert("Failed To Load the Data");
	});
	}else{
		jAlert("Please Select Reference Number And Supplier Name");
	}

});
$("#reflistid").change(function(){
	var refno=$("#reflistid").val();
	if(refno!=null){
		$("#ajaxLoader").show();
	$.ajax({
		url:"<%=application.getContextPath()%>/purchaseOrder/searchSuppliers.do",
		data:"refno="+refno,
		success:function(res){
			var e2=document.getElementById('supplierid');
			$('#supplierid')
		    .find('option')
		    .remove()
		    .end();
			var temp=res.split(",");
			if(temp != null || temp!=" "){
				var o=document.createElement('option');
				o.value="";
				o.text="Please Select";
				e2.options.add(o);
				for(var i=0;i<temp.length;i++){
					var o=document.createElement('option');
					o.value=temp[i];
					o.text=temp[i];
					e2.options.add(o);
				}
			}
			
			
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
		/* alert("Ajax Loading Completed"); */
	}).fail(function(html){
		$("#ajaxLoader").hide();
		alert("Failed To Load the Data");
	});
	}else{
		jAlert("Please Select Reference Number");
	}
});

function validate(){
	var tc=$("#tc").val();
	  if(tc==0){
		  $("#tc").val(1);
		  jAlert("Please Check the Terms And Conditions");
		  return false;
	  }
	var refno=$("#reflistid").val();
	var supplierName=$("#supplierid").val();
	if(refno==null || refno=="" || supplierName==null || supplierName==""){
		jAlert("Please Select Reference Number And Supplier Name");
		return false;
	}
}



</script>

<script language="JavaScript" type="text/javascript">
function processFormData(){
  var frmvalidator  = new Validator("form1");
  
  var rowcount=document.getElementById("rowcountid");
  var rowc=rowcount.value;
//alert("the rowcount value is"+rowc);
  for(var i=1;i<=rowc;i++)
	  {
  frmvalidator.addValidation("partno"+i,"req","Please enter PartNo"+i+"");
  /* frmvalidator.addValidation("partno"+i,"maxlen=30",	"Max length for partno"+i+" is 30");
  frmvalidator.addValidation("partno"+i,"alphanumeric","partno"+i+"Only alpha and Numeric chars only"); */
  
  frmvalidator.addValidation("make"+i,"req","Please enter made by"+i);
  frmvalidator.addValidation("make"+i,"maxlen=30","Max length of made by"+i+"is 30 ");
  
  frmvalidator.addValidation("required"+i,"req","Please enter Required"+i+" Quantity");
  frmvalidator.addValidation("required"+i,"numeric");
  
  frmvalidator.addValidation("source"+i,"req","source"+i+" must not be empty");
  /*   frmvalidator.addValidation("source"+i,"maxlen=50","maximum  length of source"+i+" is 50");
    frmvalidator.addValidation("source"+i,"alphabetic_space","Source"+i+" must be characters"); */
    
  frmvalidator.addValidation("supplier"+i,"req","supplier"+i+" must not be empty");
 /*  frmvalidator.addValidation("supplier"+i,"alphabetic_space");
   */
  frmvalidator.addValidation("uvalue"+i,"req","unit price must not be empty");
  frmvalidator.addValidation("uvalue"+i,"numeric","uvalue must be number");
  
  frmvalidator.addValidation("fright"+i,"req","fright"+i+" must not be empty");
  frmvalidator.addValidation("fright"+i,"numeric","fright"+i+" value must be numeric");
 
  
  frmvalidator.addValidation("assesable"+i,"req","Assesable"+i+" must not be empty");
  frmvalidator.addValidation("assesable"+i,"numeric","Assesable"+i+" must be numeric");
  
  frmvalidator.addValidation("bcd"+i,"req"," BCD"+i+"must not be empty");
  frmvalidator.addValidation("bcd"+i,"numeric","BCD"+i+" must be numeric");
  
  frmvalidator.addValidation("stot"+i,"req","Sub Total"+i+" must not be empty");
  frmvalidator.addValidation("stot"+i,"numeric","Sub Total"+i+" must be numeric");
  
  frmvalidator.addValidation("margin"+i,"req","Margin"+i+"must not be empty");
  frmvalidator.addValidation("margin"+i,"numeric","Margin"+i+" must be numeric");
  
  frmvalidator.addValidation("quotprice"+i,"req","Quotation"+i+" price must not be empty");
  frmvalidator.addValidation("quotprice"+i,"numeric","Quotation"+i+" must be numeric");
  
 
	  }
}
</script>
